let uid = localStorage.getItem('uid')
let list = document.querySelectorAll('.list-one-main')
function listfn(box, num) {
    let connector = `http://jx.xuzhixiang.top/ap/api/allproductlist.php?pagesize=5&pagenum=${num}&id=${uid}
    `;
    let xhr = new XMLHttpRequest();
    xhr.open("get", connector);
    xhr.send();
    xhr.onload = function () {
        let html = ''
        if (xhr.status === 200) {
            let obj = JSON.parse(xhr.responseText)
            console.log(obj);
            for (let i = 0; i < 4; i++) {
                // console.log(obj.data[i]);
                html += `
                <div class="list-one" pid="${obj.data[i].pid}">
                    <div class="list-img-up">
                        <div class="mask">中国制造</div>
                        <img src="${obj.data[i].pimg}" alt="">
                    </div>
                    <div class="list-img-down">
                        <img src="${obj.data[i + 1].pimg}" alt="">
                    </div>
                    <div class="list-one-news-con">
                        <h3>${obj.data[i].pname}</h3>
                        <h3>${obj.data[i].pname} 16g*12</h3>
                        <div class="con-price">￥${obj.data[i].pprice}</div>
                        <p>最新精选，你值得拥有</p>
                    </div>
                </div>
                `
            }

        }
        //获取 li 标签

        box.innerHTML += html
        // list[0].innerHTML += html
        let listone = document.querySelectorAll('.list-one-main .list-one')
        console.log(listone);
        listone.forEach((v, i) => {
            let pid = v.getAttribute('pid')
            v.onclick = function () {
                location.href = `./particulars.html?pid=${pid}`
            }
        })
    }
}
listfn(list[0], 8)
listfn(list[1], 9)
listfn(list[2], 10)
listfn(list[3], 11)